{!! Html::style(env("APP_URL").'/assets/backend/libs/webuploader-0.1.5/webuploader.css') !!}

<div class="ibox float-e-margins">
    <div class="ibox-content" style="display: block;">
        {!! Form::open(['route' => 'admin.shop.list.store.save', 'class' => 'form-horizontal', 'id'=> 'create-store-form', 'role' => 'form', 'method' => 'post', 'files' => true]) !!}

        <div class="form-group">
            <label for="store-name" class="col-md-2 control-label">
                <span style="color: red">*</span>门店名：
            </label>
            <div class="col-lg-10">
                {!! Form::text('store-name', isset($store) && !empty($store->name) ? $store->name : null, ['class' => 'form-control', 'placeholder' => '', 'required']) !!}
            </div>
        </div>

        <div class="form-group">
            <label for="store-city" class="col-md-2 control-label">
                <span style="color: red">*</span>所属城市：
            </label>
            <div class="col-lg-10">
                {!! Form::select('store-city', $citys, isset($store) && !empty($store->city_id) ? $store->city_id : null, ['class' => 'form-control', 'placeholder' =>'', 'required', 'id'=>'store_city']) !!}

            </div>
        </div>
        <div class="form-group">
            <label for="store-address" class="col-md-2 control-label">
                <span style="color: red">*</span>地址信息：
            </label>
            <div class="col-lg-10">
                {!! Form::text('store-address', isset($store) && !empty($store->address) ? $store->address : null, ['class' => 'form-control', 'placeholder' =>'某省某市某路某号', 'required']) !!}
            </div>
        </div>

        <div class="form-group">
            {!! Form::label('store-phone', '联系电话', ['class' => 'col-lg-2 control-label']) !!}
            <div class="col-lg-10">
                {!! Form::text('store-phone', isset($store) && !empty($store->phone) ? $store->phone : null, ['class' => 'form-control', 'placeholder' =>'']) !!}
            </div>
        </div>

        <div class="form-group">
            {!! Form::label('store-img', '店铺图片', ['class' => 'col-lg-2 control-label']) !!}
            <div class="col-lg-10">
                @if(isset($store) && !empty($store->img))
                    <img src='{!! $store->img !!}' width="100">
                    <input id="img_name" type="hidden" name="img_name" value="{!! $store->img !!}" />
                @else
                    <input id="img_name" type="hidden" name="img_name" />
                @endif

                <div id="filePicker">选择图片</div>
                <div class="clearfix"></div>
            </div>
        </div>

        <div class="form-group">
            {!! Form::label('store-code', '门店代码', ['class' => 'col-lg-2 control-label']) !!}
            <div class="col-lg-10">
                {!! Form::text('store-code', isset($store) && !empty($store->code) ? $store->code : null, ['class' => 'form-control', 'placeholder' =>'']) !!}
            </div>
        </div>

        <div class="form-group">
            {!! Form::label('store-is_enable', '是否启用', ['class' => 'col-lg-2 control-label']) !!}
            <div class="col-lg-10">
                <input type="radio" name="store-is_enable" value="1"
                       @if(isset($store) && !empty($store) && $store->is_enable ==1) checked @endif>是
                <input type="radio" name="store-is_enable" value="0"
                       @if(isset($store) && !empty($store) && $store->is_enable ==0) checked @endif>否
            </div>
        </div>

        <div class="form-group">
            {!! Form::label('store-top', '是否置顶', ['class' => 'col-lg-2 control-label']) !!}
            <div class="col-lg-10">
                <input type="radio" name="store-top" value="1"
                       @if(isset($store) && !empty($store) && $store->top ==1) checked @endif>是
                <input type="radio" name="store-top" value="0"
                       @if(isset($store) && !empty($store) && $store->top ==0) checked @endif>否
            </div>
        </div><!--form control-->

        <div class="form-group">
            <div class="col-lg-10">
                {!! Form::hidden('store-id', isset($store) && !empty($store->id) ? $store->id : null) !!}
            </div>
        </div>

        <div class="well">
            <div class="pull-right">
                <input type="submit" class="btn btn-success" value="保存" />
            </div>
            <div class="clearfix"></div>
        </div><!--well-->

        {!! Form::close() !!}
    </div>
</div>


{!! Html::script(env("APP_URL").'/assets/backend/libs/webuploader-0.1.5/webuploader.js') !!}
<script>
    $('#store_city').select2({
	    placeholder: '请选择所属城市',
	    allowClear: true,
    });

    $(document).ready(function () {

	    $('#create-store-form').ajaxForm({
		    success: function (result) {
			    if (200 == result.code) {
				    swal({
					    title: "保存成功！",
					    text: "",
					    type: "success"
				    }, function () {
					    window.location = '{{route('admin.shop.list.store')}}';
				    });
			    } else {
				    swal("保存失败!", result.message, "error")
			    }

		    }
	    });

	    // 初始化Web Uploader
	    var uploader = WebUploader.create({
		    auto: true,
		    swf: '{{url(env("APP_URL").'/assets/backend/libs/webuploader-0.1.5/Uploader.swf')}}',
		    server: '{{route('upload.image',['_token'=>csrf_token()])}}',
		    pick: '#filePicker',
		    fileVal: 'upload_image',
		    accept: {
			    title: 'Images',
			    extensions: 'gif,jpg,jpeg,bmp,png',
			    mimeTypes: 'image/*'
		    }
	    });
	    // 文件上传成功，给item添加成功class, 用样式标记上传成功。
	    uploader.on('uploadSuccess', function (file, response) {
		    $('#img_name').val(response.url);
	    });
    });
</script>